package logic

import (
	"context"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/renrenzu"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListOneLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListOneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListOneLogic {
	return &GoodsListOneLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListOneLogic) GoodsListOne(in *renrenzu.GoodsListOneRequest) (*renrenzu.GoodsListOneResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}
	list, err := g.GoodsListOne(int(in.GoodsId))
	if err != nil {
		return nil, err
	}
	lists := []*renrenzu.GoodsList{}
	for _, v := range list {
		lists = append(lists, &renrenzu.GoodsList{
			GoodsTitle:      v.GoodsTitle,
			GoodsCover:      v.GoodsCover,
			GoodsPrice:      float32(v.GoodsPrice),
			GoodsStock:      int64(v.GoodsStock),
			GoodsCollection: int64(v.GoodsCollection),
			GoodsState:      int64(v.GoodsState),
		})
	}
	return &renrenzu.GoodsListOneResponse{List: lists}, nil
}
